package net.blf2.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.blf2.mybatisplus.entity.User;
import org.apache.ibatis.annotations.*;

public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * from user u " +
            "inner join company c " +
            "on u.company_id = c.company_id " +
            "where u.id = #{id};")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "age",property = "age"),
            @Result(column = "email",property = "email"),
            @Result(column = "company_id",property = "companyId"),
            @Result(column = "company_id",property = "company.companyId"),
            @Result(column = "company_name",property = "company.companyName")
    })
    User selectOneIncludeCompany(String id);

    @Select("SELECT * from user u " +
     //       "inner join company c " +
    //        "on u.company_id = c.company_id " +
            "where u.id = #{id};")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "age",property = "age"),
            @Result(column = "email",property = "email"),
            @Result(column = "company_id",property = "companyId"),
            @Result(column = "company_id",property = "company",one = @One(select = "net.blf2.mybatisplus.mapper.CompanyMapper.selectById"))
    })
    User selectOneIncludeCompany2(String id);

    User selectOneBySqlInject(@Param("id") String id, @Param("sex") Integer sex);
}
